package mylab.base.model.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import mylab.annotation.rds.ColumnComment;
import mylab.base.IdName;
import mylab.base.constants.DbConst;

import java.io.Serializable;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@TableName(autoResultMap = true)
public abstract class Entity<K extends Serializable> implements IdName<K> {

    /**
     * 名称
     */
    @ColumnComment("名称")
    @ApiModelProperty(value = "名称")
    @TableField
    protected String name;

    /**
     * 租户id
     */
    @JsonIgnore
    @ColumnComment("租户id")
    @ApiModelProperty(value = "租户id", notes = "多租户COLUMN模式时必须，其它模式时为冗余设计")
    @TableField(value = DbConst.TENANT_ID_COLUMN)
    protected Long tenantId;

    /**
     * 启用状态标识
     */
    @ColumnComment("启用状态标识")
    @ApiModelProperty("启用状态标识")
    @TableField(value = DbConst.COLUMN_INVALID)
    protected Boolean invalid = false;

    /**
     * 扩展属性
     */
    @ColumnComment("扩展属性")
    @ApiModelProperty("扩展属性")
    @TableField(value = DbConst.COLUMN_EXTRA)
    protected String extra;

    /**
     * 备注
     */
    @ColumnComment("备注")
    @ApiModelProperty("备注")
    @TableField(value = DbConst.COLUMN_COMMENTS)
    protected String comments;

    /**
     * 版本号(乐观锁)
     */
    @JsonIgnore
    @ColumnComment("乐观锁")
    @Version
    @TableField(value = DbConst.COLUMN_VERSION)
    protected Integer version = 0;

    /**
     * 逻辑删除标识
     * <p>
     * 1、只对自动注入的sql起效
     * 2、对mapper中的自定义方法无效
     * 3、对mybatis原生的 @Select @Delete 无效
     * </p>
     */
    @JsonIgnore
    @ColumnComment("逻辑删除标记")
    @TableLogic
    @TableField(value = DbConst.COLUMN_DELETED)
    protected Boolean deleted = false;

    @JsonIgnore
    @ColumnComment("所有者信息")
    @ApiModelProperty("所有者信息")
    @TableField(value = DbConst.COLUMN_OWNER, fill = FieldFill.INSERT)
    protected String owner;

    @JsonIgnore
    @ColumnComment("创建者信息")
    @ApiModelProperty("创建者信息")
    @TableField(value = DbConst.COLUMN_CREATER, fill = FieldFill.INSERT)
    protected String creater;

    @JsonIgnore
    @ColumnComment("更新者信息")
    @ApiModelProperty("更新者信息")
    @TableField(value = DbConst.COLUMN_UPDATER, fill = FieldFill.INSERT_UPDATE)
    protected String updater;

}
